/**
 * 
 */
package org.xlab.baseframework.conf;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.xlab.baseframework.web.BaseframeworkApplication;
import org.xlab.baseframework.web.component.CodeEditWindow;
import org.xlab.baseframework.web.component.CodeFunctionLayout;
import org.xlab.baseframework.web.component.LoginLayout;
import org.xlab.baseframework.web.component.SystemMainWindow;
import org.xlab.baseframework.web.component.TopMenuLayout;

import com.vaadin.Application;
import com.vaadin.ui.Component;

/**
 * @author MaKuBEX
 * 
 */
@Configuration
public class WebConfigration {
	@Bean(autowire = Autowire.BY_NAME, name = "bpf_app")
	@Scope("request")
	@DependsOn(value = { "bpf_systemMainWindow" })
	public Application baseframeworkApplication() {
		return new BaseframeworkApplication(systemMainWindow());
	}

	@Bean(autowire = Autowire.BY_NAME, name = "bpf_codeEditWindow")
	@Lazy(value = true)
	public Component codeEditWindow() {
		return new CodeEditWindow("Edit System Code");
	}

	@Bean(autowire = Autowire.BY_NAME, name = "bpf_codeFunctionLayout")
	@Lazy(value = true)
	public Component codeFunctionLayout() {
		return new CodeFunctionLayout();
	}

	@Bean(autowire = Autowire.BY_NAME, name = "bpf_loginLayout")
	public Component loginLayout() {
		return new LoginLayout();
	}

	@Bean(autowire = Autowire.BY_NAME, name = "localeResolver")
	public LocaleResolver sessionLocaleResolver() {
		SessionLocaleResolver localeResolver = new SessionLocaleResolver();
		localeResolver.setDefaultLocale(Locale.US);
		return localeResolver;
	}

	@Bean(autowire = Autowire.BY_NAME, name = "bpf_systemMainWindow")
	public SystemMainWindow systemMainWindow() {
		return new SystemMainWindow("Welcome to XLab.org");
	}

	@Bean(autowire = Autowire.BY_NAME, name = "bpf_topMenuLayout")
	public Component topMenuLayout() {
		return new TopMenuLayout();
	}
}
